package com.telchina.data.meterReading.controller;

import com.alibaba.fastjson2.JSON;
import com.telchina.data.meterReading.entity.MeterReading;
import com.telchina.data.meterReading.service.IMeterreadingService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.telchina.common.annotation.Log;
import com.telchina.common.core.controller.BaseController;
import com.telchina.common.core.domain.AjaxResult;
import com.telchina.common.enums.BusinessType;


/**
 * 水表读数(Meterreading)表控制层
 *
 * @author 郝振
 * @since 2023-06-16 17:38:43
 */
@RestController
@RequestMapping("/data/meterreading")
public class MeterreadingController extends BaseController {
    /**
     * 服务对象
     */

    private final IMeterreadingService meterreadingService;

    @Autowired
    public MeterreadingController(IMeterreadingService meterreadingService) {
        this.meterreadingService = meterreadingService;
    }

//    /**
//     * 分页查询
//     *
//     * @param meterreading 筛选条件
//     */
//    @GetMapping("/list")
//    public AjaxResult list(MeterReading meterreading) {
//        startPage();
//        List<Meterreading> list = meterreadingService.selectMeterreadingList(meterreading);
//        return getDataTable(list);
//    }

    /**
     * 获取详情
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo(String id) {
        return AjaxResult.success(meterreadingService.getById(id));
    }

    /**
     * 新增水表读数
     *
     * @param meterreading 实体
     */
    @Log(title = "水表读数管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MeterReading meterreading) {
        return toAjax(meterreadingService.save(meterreading));
    }

    /**
     * 编辑水表读数
     *
     * @param meterreading 实体
     */
    @Log(title = "水表读数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody MeterReading meterreading) {
        return toAjax(meterreadingService.updateById(meterreading));
    }

    /**
     * 删除水表读数
     *
     * @param ids 主键
     */
    @Log(title = "水表读数", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestBody String ids) {
        return success(meterreadingService.removeByIds(JSON.parseObject(ids, List.class)));
    }


}

